/*
 * *
 *  * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 *
 *
 */

package com.iwindplus.aider.web.autoconfigure;

import com.iwindplus.aider.web.domain.property.AiderWebProperty;
import com.iwindplus.aider.web.service.OperateLogServiceImpl;
import com.iwindplus.aider.web.service.OperateValidServiceImpl;
import com.iwindplus.boot.operate.service.OperateLogService;
import com.iwindplus.boot.operate.service.OperateValidService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * web 助手配置.
 *
 * @author zengdegui
 * @since 2018/9/1
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(AiderWebProperty.class)
@ConditionalOnProperty(prefix = "aider", name = "enabled", havingValue = "true", matchIfMissing = true)
public class AiderWebAutoConfiguration {

    /**
     * 创建 OperateLogService.
     *
     * @return OperateLogService
     */
    @Bean
    @ConditionalOnProperty(prefix = "aider.operate.log", name = "enabled", havingValue = "true", matchIfMissing = true)
    public OperateLogService operateLogService() {
        final OperateLogServiceImpl operateLogService = new OperateLogServiceImpl();
        log.info("OperateLogService={}", operateLogService);
        return operateLogService;
    }

    /**
     * 创建 OperateValidService.
     *
     * @return OperateValidService
     */
    @Bean
    @ConditionalOnProperty(prefix = "aider.operate.valid", name = "enabled", havingValue = "true", matchIfMissing = true)
    public OperateValidService operateValidService() {
        final OperateValidServiceImpl operateValidService = new OperateValidServiceImpl();
        log.info("OperateValidService={}", operateValidService);
        return operateValidService;
    }
}
